25. Determine Probabilities

To implement these models in code, we need a function to which we can pass model parameters/values and return a probability. Fortunately, we can use a normalized probability density function (PDF). Let's revisit Sebastian's discussion of this topic.

We have implemented this Gaussian Distribution as a C++ function, normpdf, and will practice using it at the end of this concept. normpdf accepts a value, a parameter, and a standard deviation, returning a probability.

Additional Resources for Gaussian Distributions

Let's practice using normpdf to determine transition model probabilities. Specifically, we need to determine the probability of moving from x_{t-1} --> x_t. The value entered into normpdf will be the distance between these two positions. We will refer to potential values of these positions as pseudo position and pre-pseudo position. For example, if our pseudo position x is 8 and our pre-pseudo position is 5, our sample value will be 3, and our transition will be from x - 3 --> x.

To calculate our transition model probability, pass any difference in distances into normpdf along with our control parameter and position standard deviation.

Maximize Gaussian

Given pseudo position x and a control parameter of 1 (move 1 unit each time step), which pre-pseudo position maximizes our probability?

Start Quiz:

//=================================================================================
// Name        : help_functions.h
// Version     : 2.0.0
// Copyright   : Udacity
//=================================================================================

#include <iostream>
#include "help_functions.h"

//TODO: assign a value, the difference in distances between x_t and x_{t-1}
//that maximizes the returned probability of norm_pdf

float value = ?;//YOUR VALUE HERE


float parameter = 1.0; //set as control parameter or observation measurement
float stdev = 1.0; //position or observation standard deviation

int main() {

    float prob = Helpers::normpdf(value, parameter, stdev);

    std::cout << prob << endl;

    return 0;
}
//=================================================================================
// Name        : help_functions.h
// Version     : 2.0.0
// Copyright   : Udacity
//=================================================================================

#ifndef HELP_FUNCTIONS_H_
#define HELP_FUNCTIONS_H_

#include <math.h>
#include <iostream>
#include <vector>

using namespace std;

class Helpers {
public:

	//definition of one over square root of 2*pi:
	constexpr static float STATIC_ONE_OVER_SQRT_2PI = 1/sqrt(2*M_PI) ;
	float ONE_OVER_SQRT_2PI = 1/sqrt(2*M_PI) ;

	/*****************************************************************************
	 * normpdf(X,mu,sigma) computes the probability function at values x using the
	 * normal distribution with mean mu and standard deviation std. x, mue and 
	 * sigma must be scalar! The parameter std must be positive. 
	 * The normal pdf is y=f(x;mu,std)= 1/(std*sqrt(2pi)) e[ -(x−mu)^2 / 2*std^2 ]
	*****************************************************************************/
	static float normpdf(float x, float mu, float std) {
	    return (STATIC_ONE_OVER_SQRT_2PI/std)*exp(-0.5*pow((x-mu)/std,2));
	}
	
};

#endif /* HELP_FUNCTIONS_H_ */